<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="crm.util.ParamUtil"%>
<%@page import="crm.control.EmployeesControl"%>
<%@page import="crm.model.Employees"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>用户登入</title>
	</head>
	<body>
<%
	String username = request.getParameter("username");
	String pwd =  request.getParameter("password");
	//System.out.print(EmployeesControl.isEmployees(username, pwd));
	 //if(rand.equals(input)){
	if(session.getAttribute("user")!=null){
	%>
	<script>
	      alert("你尚未退出，若要重新登陆请先退出已登陆账号");
	       window.location.href="logout.jsp";
	</script>
	<%}else{
	       if (EmployeesControl.getUid(username,pwd)!=0) {
			        int uid = EmployeesControl.getUid(username,pwd);
					session.setAttribute("userid",uid); 
					Employees  u =EmployeesControl.getEmpolyeesById(uid);
					session.setAttribute("user",u); 
					session.setAttribute("role",u.getPosition());
					if(u.getPosition()==0)
					response.sendRedirect("../common/recepit/show_all_recepits.jsp");
					if(u.getPosition()==1)
					response.sendRedirect("../common/recepit/show_all_recepits.jsp");
					if(u.getPosition()==2)
					response.sendRedirect("../common/recepit/show_all_recepits.jsp");
					if(u.getPosition()==3)
					response.sendRedirect("../common/recepit/show_all_recepits.jsp");
		} else {
%>
	<script type="text/javascript">
		alert("用户名或密码错误,请重新输入！");
		history.go(-1);
	</script>
<% }}
%>

	</body>
</html>
